﻿@using CodeGenerator.Core
@using System.Text
@{
    int count = 0;
    string primaryKey = "";
    TableInfo table = Model.TableInfo;
}
using HPK.Util;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HPK.Application.Entity
{
@if (!string.IsNullOrEmpty(table.Comments))
{
    @:/// <summary>
    @:/// @table.Comments
    @:/// </summary>
}
    [SugarTable("@table.Name")]
    public class @(Model.Name)Entity : BaseEntity
    {
    	#region 实体
    @foreach (ColumnInfo column in table.ColumnList)
    {
        if (!string.IsNullOrEmpty(column.Comments))
        {
        @:/// <summary>
        @:/// @column.Comments
        @:/// </summary>
        @:///<returns></returns>
        }
        if (column.IsPrimaryKey == "是")
        {
   		@:[SugarColumn(IsPrimaryKey = true)]
        }
    	@:public @column.NetType.Alias @column.Name { get; set; }
    	@:
    }
    	#endregion

    	#region 扩展操作
        /// <summary>
    	/// 新增调用
    	/// </summary>
    	public override void Create()
    	{
		@foreach (ColumnInfo column in table.PrimaryKeyColumns)
		{
		  if(column.NetType.Alias!="int")
		   {
		   @:this.@column.Name = CommonHelper.GetGuid;
		   }
		   else
		   {
		   @:this.@column.Name = null;
		   }
		}
		@foreach (ColumnInfo column in table.ColumnList)
		{
		   if(column.Name.ToLower()=="createdate")
		   {
		   @:this.@column.Name = DateTime.Now;
		   }
		   if (column.Name.ToLower() == "createuserid")
		   {
		   @:this.@column.Name = OperatorProvider.Provider.Current().UserId;
		   }
		   if (column.Name.ToLower() == "createusername")
		   {
		   @:this.@column.Name = OperatorProvider.Provider.Current().UserName;
		  }
		}
		}
    	/// <summary>
        /// 编辑调用
        /// </summary>
    	/// <param name="keyValue"></param>
    	public override void Modify(string keyValue)
    	{
		@foreach (ColumnInfo column in table.PrimaryKeyColumns)
		{
		   if (!column.IsNumeric)
		   {
		   @:this.@column.Name = keyValue;
		   }
		   else
		   {
		   @:this.@column.Name = CommonHelper.GetInt(keyValue);
		   }
		}
		@foreach (ColumnInfo column in table.ColumnList)
		{
		   if (column.Name.ToLower() == "modifydate")
		   {
		   @:this.@column.Name = DateTime.Now;
		   }
		   if (column.Name.ToLower() == "modifyuserid")
		   {
		   @:this.@column.Name = OperatorProvider.Provider.Current().UserId;
		   }
		   if (column.Name.ToLower() == "modifyusername")
		   {
		   @:this.@column.Name = OperatorProvider.Provider.Current().UserName;
		   }
		}
		}
    	#endregion
    }
}

